/**
 * Author: Shen Yanqiu
 * Date: 2017-12-07
 * Time: 16:24
 *
 */
import React from 'react';
import { routerTool } from 'utils';
import { routerRedux } from 'dva/router';
import PropTypes from 'prop-types';
import { connect } from 'dva';
import { Page, OperationBoard } from 'components';
import queryString from "query-string";
import { List, Operation, Action, BatchAction } from './Components';

class Activity extends React.Component {
  static propTypes = {
    loading: PropTypes.object,
    dispatch: PropTypes.func,
    activity: PropTypes.object,
    location: PropTypes.object,
  };

  _handleCreate = () => {
    console.log("click create btn");
    const { dispatch } = this.props;
    dispatch(routerTool.redirectTo('AddActivity'));
  }

  render () {
    const { loading, location, activity, dispatch } = this.props;
    location.query = queryString.parse(location.search);
    const { list, pagination } = activity;
    const listProps = {
      dataSource: list,
      loading: loading.effects['activity/getActivityList'],
      pagination,

      onChange (_pagination) {
        const { query, pathname } = location;
        dispatch({
          type: 'activity/getActivityList',
          payload: {
            ...query,
            current: _pagination.current,
            pageSize: _pagination.pageSize,
          },
        });
      },

      onSeeItem (record) {
        dispatch({
          type: 'activity/onSeeItemModal',
          payload: {
            id: record.id,
          },
        });
      },

      onDeleteItem (id, record) {
        dispatch({
          type: 'activity/onDeleteItemModal',
          payload: {
            id,
          },
        });
      },

    };
    function SearchData (data) {
      dispatch({
        type: 'activity/searchData',
        payload: {
          formData: data,
        },
      });
    }
    function clickHandle () {
      dispatch(routerTool.redirectTo({
        name: 'AddActivity',
      }));
    }
    return (
      <Page loading={loading.models.activity} inner >
        {/* <Operation SearchData={SearchData} />
        <TopRightButton contentText="添加活动" clickHandle={clickHandle} /> */}
        <OperationBoard
          // filter={<span>Hello</span>}
          batchAction={<BatchAction />}
        >
          <Action onCreateClick={this._handleCreate} />
          {/* <span>Action</span> */}
        </OperationBoard>
        <List {...listProps} />

      </Page>
    );
  }
}
export default connect(({ loading, activity }) => ({ loading, activity }))(Activity);
